﻿/**
 * Stardust Particle Engine
 * 
 * Homepage
 * 	http://code.google.com/p/stardust-particle-engine/
 * 
 * PDF Manual
 * 	http://stardust-particle-engine.googlecode.com/svn/trunk/manual/Stardust%20Particle%20Engine%20Manual.pdf
 */

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import idv.cjcat.stardust.common.particles.ParticleList;
	import idv.cjcat.stardust.common.renderers.Renderer;
	import idv.cjcat.stardust.twoD.renderers.DisplayObjectRenderer;
	
	[SWF(backgroundColor="#000000", frameRate=60)]
	
	public class Main extends Sprite {
		
		private var ROWS:int = 7;
		
		private var container:Sprite;
		private var emitter:BoxEmitter;
		
		public function Main() {
			container = addChild(new Sprite());
			
			emitter = new BoxEmitter(null);
			var renderer:Renderer = new DisplayObjectRenderer(container);
			renderer.addEmitter(emitter);
			
			buildParticles();
		}
		
		private function buildParticles():void {
			var particles:ParticleList = new ParticleList();
			
		}
		
		private function restore(e:Event):void {
			emitter.restorer.start();
		}
	}
}

//------------------------------------------------------------------------------------------------

import flash.display.Shape;
import idv.cjcat.stardust.common.clocks.Clock;
import idv.cjcat.stardust.common.easing.Strong;
import idv.cjcat.stardust.common.math.UniformRandom;
import idv.cjcat.stardust.twoD.actions.SnapshotRestore;
import idv.cjcat.stardust.twoD.actions.SnapshotRestoreFlag;
import idv.cjcat.stardust.twoD.emitters.Emitter2D;

//------------------------------------------------------------------------------------------------

const RESTORE_CURVE:Function = Strong.easeOut;
const RESTORE_DURATION_AVG:Number = 50;
const RESTORE_DURATION_VAR:Number = 20;

//------------------------------------------------------------------------------------------------

class BoxEmitter extends Emitter2D {
	
	public var restorer:SnapshotRestore;
	
	public function BoxEmitter(clock:Clock) {
		super(clock);
		
		restorer = new SnapshotRestore();
		restorer.duration = new UniformRandom(RESTORE_DURATION_AVG, RESTORE_DURATION_VAR);
		restorer.flags = SnapshotRestoreFlag.POSITION | SnapshotRestoreFlag.ROTATION;
		restorer.curve = RESTORE_CURVE;
		
		addAction(restorer);
	}
}

//------------------------------------------------------------------------------------------------

class Box extends Shape {
	
	private static const SIZE:Number = 20;
	private static const HALF_SIZE:Number = 0.5 * SIZE;
	
	public function Box() {
		graphics.beginFill(0);
		graphics.drawRect( -HALF_SIZE, -HALF_SIZE, SIZE, SIZE);
	}
}